import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    uid:0,  // 当前用户id
    phone: "", // 用户手机号
    setting:[], //系统配置
    publish_person:[],   //当系统不对外开放发红包功能时，可发红包人员的uid列表
    area:[],  //用户地址信息，省，市，区
    link_name:"", //用户推广的链接信息
    media:{   //素材库props
      show:false,
      value:[],
      select:true,
      type:"all",
      onClose:()=>{},
      onSelect:()=>{}
    },
    poster:{  //海报组件props
      show:false,
      value:"",
      assist_value:"",
      assist_text:"",
      onClose:()=>{}
    },
    page:{  //全局外部页面组件props
      show:false,
      src:"",
      onClose:()=>{}
    },
    // 分享
    share: {
      uid: 0,
      red_id: 0
    }
  },
  getters:{
    medias:state=>(attr)=>{
      return state.media[attr];
    },
    posters:state=>(attr)=>{
      return state.poster[attr];
    },
    pages:state=>(attr)=>{
      return state.page[attr];
    }
  },
  mutations: {
    setShare(state,value){
      state.share = value
    },
    setUid(state,value){
      state.uid = value;
    },
    setSetting(state,value){
      state.setting = value;
    },
    setPublishPerson(state,value){
      state.publish_person = value;
    },
    setArea(state,value){
      state.area = value;
    },
    setMedia(state,value){
      let new_value = Object.assign(state.media,value);
      state.media = new_value;
    },
    setPoster(state,value){
      let new_value = Object.assign(state.poster,value);
      state.poster = new_value;
    },
    setPage(state,value){
      let new_value = Object.assign(state.page,value);
      state.page = new_value;
    },
    setLinkName(state,value){
      state.link_name = value;
    },
    // 用户手机号设置
    setPhone (state, value) {
      state.phone = value
    }
  }
})
